﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Net;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace web
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }
        public String[] webClientMethod1()
        {
            WebClient wc = new WebClient();
            wc.Encoding = Encoding.UTF8;
            //以字符串的形式返回数据
            string html = wc.DownloadString("https://www.cnki.net/");

            //以正则表达式的形式匹配到字符串网页中的邮箱
            MatchCollection matches = Regex.Matches(html, @"\w[-\w.+]*@([A-Za-z0-9][-A-Za-z0-9]+\.)+[A-Za-z]{2,14}");
            //依次取得匹配到的数据
            String[] s = new String[2];
            s[0] = "";
            int i = 0;
            foreach (Match item in matches)
            {

                s[0] += item.Groups[i].Value;
                i++;
            }
            //以正则表达式的形式匹配到字符串网页中的电话

            MatchCollection matches1 = Regex.Matches(html, "d{3}-d{3}-d{4}");
            //依次取得匹配到的数据
            s[1] = "";
            int j = 0;
            foreach (Match item in matches1)
            {

                s[1] += item.ToString();

            }
            return s;

        }

        private void button1_Click(object sender, EventArgs e)
        {
            String[] s = this.webClientMethod1();
            this.textBox2.Text = "邮箱：" + s[0] + "\r\n" + "电话：" + s[1];

        }
    }

}
